<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Base\LogServerEverydayData;
use App\Models\Base\ServerList;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class ServerSingleController extends Controller
{
    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.data_statistic'));
            $content->description(trans('game.base_data'));

            $content->body($this->grid());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(LogServerEverydayData::class, function (Grid $grid) {
            $grid->date_time(trans('game.date'))->sortable();
            $grid->serverName()->name(trans('game.server_name'));
            $grid->login_player_num(trans('game.login_user_number'));
            $grid->new_role_num(trans('game.new_role'));
            $grid->amount(trans('game.amount'));
            $grid->pay_player_num(trans('game.pay_user_number'));
            $grid->pay_player_ratio(trans('game.pay_rate'));
            $grid->new_player_pay_num(trans('game.pay_new_user_no'));
            $grid->new_player_amount(trans('game.new_user_amount'));
            $grid->new_player_ltv(trans('game.new_user_one_day_ltv'));
            $grid->old_player_pay_num(trans('game.pay_old_user_no'));
            $grid->old_player_amount(trans('game.old_user_amount'));
            $grid->online_max_num(trans('game.max_online'));
            $grid->online_min_num(trans('game.min_online'));
            $grid->online_avg_num(trans('game.avg_online'));
            $grid->arpu('Arpu');
            $grid->arppu('Arppu');
            $grid->disableActions();
            $grid->disableCreateButton();
            $grid->tools(function ($tools) {
                $tools->batch(function ($batch) {
                    $batch->disableDelete();
                });
            });
            $grid->filter(function ($filter) {
                // 去掉默认的id过滤器
                $filter->disableIdFilter();
                $filter->equal('server_id', trans('game.server_name'))->select(ServerList::all()->pluck('name', 'server_id'));
                $filter->between('date_time', trans('game.date'))->date();
            });
        });
    }
}
